package com.example.day02.luckfrag;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.example.day02.R;
import com.example.day02.startfrag.StarInfo;
import com.example.day02.utils.AssetsUtils;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;


/**
 * A simple {@link Fragment} subclass.
 */
public class LuckFragment extends Fragment {
    GridView luckGv;
    private LuckBaseAdapter adapter;
    List<StarInfo.StarinfoBean> list;
    List<String>nameList;
    public LuckFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(final LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_luck, container, false);
        luckGv=view.findViewById(R.id.luck_gv);
        //    获取数据
        nameList=new ArrayList<>();
        Bundle bundle=getArguments();
        StarInfo starInfo= (StarInfo) bundle.getSerializable("info");
        list = starInfo.getStarinfo();  //数据源
        for (int i = 0; i < list.size(); i++) {
            nameList.add(list.get(i).getName());
        }
//        创建适配器
        adapter = new LuckBaseAdapter(getContext(), list);
        luckGv.setAdapter(adapter);
        luckGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent();
                intent.setClass(getActivity(),FortuneActivity.class);
                intent.putExtra("star_name",list.get(position).getName());
                startActivity(intent);
            }
        });
        return view;
    }
}
